const fs = require('fs'); // fs 为内置模块 File System

fs.readFile('./05_modA.js', (err, data) => {
    if(err){
        console.log(err);
    } else {
        console.log(data.toString());
    }
});

console.log("==============");

fs.readFile('./06_fs.js', 'utf8', (err, data) => {
    if(err){
        console.log(err);
    } else {
        console.log(data);
    }
});

console.log("*****************");

const data = fs.readFileSync('./03_require.js', 'utf8');
console.log(data);

// 写文件
fs.writeFile('./text', 'this is a write by code.', {
    encoding: 'utf8'
}, err => {
    if (err) throw err;
    
    console.log('done');
});

fs.stat('./05_main.js', (err, stats) =>{
    if (err) throw err;

    console.log(stats.isFile());
    console.log(stats.isDirectory());
    console.log(stats);
});

fs.readdir('./', (err, files) =>{
    if (err) throw err

    console.log(files);
});